void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(D5, INPUT);
}
bool flag = true;
class Button
{
  public:
    Button(int pin);
    bool onDown();
  private:
    bool btn_flag;
    int btn_pin;
};
Button::Button(int pin)
{
  btn_pin=pin;
  btn_flag=true;
}
bool Button::onDown()
{
  bool res=false;
  if (digitalRead(btn_pin) == HIGH) {
    delay(20);
    if (digitalRead(btn_pin) == HIGH && btn_flag) res=true;
    btn_flag = false;
  }
  else btn_flag = true;
  return res;
}
Button btn(D5);
void loop() {
  // put your main code here, to run repeatedly:
  //Serial.println(digitalRead(D5));
  if(btn.onDown()) Serial.println("down!");
//  if (digitalRead(D5) == HIGH) {
//    delay(20);
//    if (digitalRead(D5) == HIGH && flag) Serial.println("tap!");
//    flag = false;
//  }
//  else flag = true;

}
